package froxy.urlfetch;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.eclipse.jetty.util.IO;

import froxy.client.Helper;

public class HttpContentCreator {
    private UrlFetch urlFetch;

    public HttpResponse getResponseDirect(HttpServletRequest request) throws ClientProtocolException, IOException {
        urlFetch = createDirectUrlFetch(request);
        // urlFetch.addObserver(SwingUI.getApplicatoin());
        return urlFetch.fetch(request);
    }

    protected UrlFetch createDirectUrlFetch(HttpServletRequest request) {
        if (request.getMethod().equals(Helper.GET)) {
            return new DirectGetUrlFetch();
        } else if (request.getMethod().equals(Helper.POST)) {
            return new DirectPostUrlFetch();
        } else {
            return new DirectGetUrlFetch();
        }
    }
}
